//
//  JOMessageCell.m
//  QQ聊天
//
//  Created by song on 15/1/14.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "JOMessageCell.h"
#import "JOMessage.h"
#import "UIImage+Resize.h"
@interface JOMessageCell()

@property(nonatomic , weak)UILabel *timeView;

@property(nonatomic , weak)UIImageView *iconView;

@property(nonatomic , weak)UIButton *textView;

@end

@implementation JOMessageCell

+(instancetype)cellWithTableView:(UITableView *)tableview
{
    NSString *ID=@"qq";
    JOMessageCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if(cell ==nil)
    {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    
    return  cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UILabel *timeview = [[UILabel alloc]init];
        //        [timeview setBackgroundColor:[UIColor blueColor]];
        timeview.textAlignment= NSTextAlignmentCenter;
        [self.contentView addSubview:timeview];
        self.timeView = timeview;
        
        UIImageView *iconView =[[UIImageView alloc]init];
        [self.contentView addSubview:iconView];
        self.iconView =iconView;
        
        UIButton *textView = [[UIButton alloc]init];
//        textView.backgroundColor  = [UIColor purpleColor];
        textView.titleLabel.font = [UIFont systemFontOfSize:14];
//        textView.titleLabel.backgroundColor =[UIColor redColor];
        [textView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        textView.titleLabel.numberOfLines = 0;
        textView.contentEdgeInsets =UIEdgeInsetsMake(20, 20, 20, 20);
        
        [self.contentView addSubview:textView];
        self.textView = textView;
        
    }
    [self setBackgroundColor:[UIColor clearColor]];
    return self;
}


//-(UIImage *)resizableImage:(NSString *)name
//{
//    UIImage *normalimg = [UIImage imageNamed:name] ;
//
//    CGFloat normalW = normalimg.size.width* 0.5;
//    CGFloat normalH = normalimg.size.height* 0.5;
//    return  [normalimg resizableImageWithCapInsets:UIEdgeInsetsMake(normalH, normalW, normalH, normalW)];
//}


-(void)setMessageFrame:(JOMessageFrame *)messageFrame
{
    _messageFrame = messageFrame;
    
    JOMessage *message = _messageFrame.message;
    self.timeView.text  = message.time;
    if (message.type == JOMessageTypeOther) {
        self.iconView.image = [UIImage imageNamed:@"other"];
    }else{
        self.iconView.image = [UIImage imageNamed:@"me"];
    }
    [self.textView setTitle:message.text forState:UIControlStateNormal];
    
    self.timeView.frame = self.messageFrame.timeF;
    self.iconView.frame = self.messageFrame.iconF;
    self.textView.frame = self.messageFrame.textF;
    
    UIImage *normalimg;
    UIImage *hightimg;
    if(message.type == JOMessageTypeMe)
    {
         normalimg =[UIImage imageResizableWithName:@"chat_send_nor"];
        hightimg = [UIImage imageResizableWithName:@"chat_send_press_pic"];
    }else{
        
        normalimg =[UIImage imageResizableWithName:@"chat_recive_nor"];
        hightimg = [UIImage imageResizableWithName:@"chat_recive_press_pic"];
    }
    
  
    
    [self.textView setBackgroundImage:normalimg   forState:UIControlStateNormal];
    [self.textView setBackgroundImage:hightimg   forState:UIControlStateHighlighted];
}



- (void)awakeFromNib
{
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    
}

@end
